$(function () {

    myGetAjax(
        "/catering_system_app/shopUser/getShopUser",
        {},
        getMyShopUser
    );

    listShopName();
    listname();
    $("#logout_1").click(function () {
        alert("11");
        logout();
    })
});
function getMyShopUser(RepVo) {
    if (RepVo.code == "200") {
        $("#myshop_1").text(RepVo.data.shopName);
        $("#myshop_2").text(RepVo.data.userName);
        $("#myshop_3").text(RepVo.data.phone);
        $("#myshop_4").text(RepVo.data.shopDivision);
        $("#myshop_5").text(RepVo.data.brandName);
        $("#myshop_6").text(RepVo.data.shopAddress);
    } else {
        alert(RepVo.msg)
    }
    $(".myshop").click(function () {
        var str = "";
        $(".myshop").attr("style", "background:white");
        $(this).attr("style", "background:#83c3ff")
        if ($(this).text() == "店铺信息") {
            str ="                            <div class='form-group'>" +
                "                                <label>商&nbsp;户&nbsp;名：</label><span id='myshop_1'></span>" +
                "                            </div>" +
                "                            <div class='form-group'>" +
                "                                <label>店&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;主：</label>" +
                "                                <spa id='myshop_2'></spa>" +
                "                            </div>" +
                "                            <div class='form-group'>" +
                "                                <label>联系方式：</label>\n" +
                "                                <spa id='myshop_3'></spa>" +
                "                            </div>" +
                "                            <div class='form-group'>" +
                "                                <label>所属区域：</label>" +
                "                                <spa id='myshop_4'></spa>" +
                "                            </div>" +
                "                            <div class='form-group'>" +
                "                                <label>所属品牌 ：</label><span id='myshop_5'></span>" +
                "                            </div>" +
                "                            <div class='form-group'>" +
                "                                <label>详细地址 ：</label><span id='myshop_6'></span>" +
                "                            </div>";
            $("#row_2_1_2").html(str);
            myGetAjax(
                "/catering_system_app/shopUser/getShopUser",
                {},
                getMyShopUser
            );
        } else if ($(this).text() == "店铺信息编辑") {
            str = " <form id='form_1'> <div class='form-group'>" +
                "       <label>店铺名</label>" +
                "       <input type='text' class='form-control' name='shopName' id='shopName'" +
                "       value='"+RepVo.data.shopName+"'>" +
                "       <span></span>" +
                "</div>" +
                "<div class='form-group'>" +
                "       <label>店铺所属区域</label>" +
                "       <input type='text' class='form-control' name='shopDivision' id='shopDivision' " +
                "       value='"+RepVo.data.shopDivision+"'>" +
                "</div>" +
                "<div class='form-group'>" +
                "       <label>店铺品牌</label>" +
                "       <input type='text' class='form-control' name='brandName' id='brandName' " +
                "       value='"+RepVo.data.brandName+"'>" +
                "</div>" +
                "<div class='form-group'>" +
                "       <label>店铺地址</label>" +
                "       <input type='text' class='form-control' name='shopAddress' id='shopAddress' " +
                "       value='"+RepVo.data.shopAddress+"'>" +
                "</div>" +
                "<div class='form-group'>" +
                "         <button type='button' class='btn btn-default btn-lg btn-warning btn-block' id='editShop'>保存</button>" +
                "</div></form>";
            $("#row_2_1_2").html(str);
        }

        $("#shopName").blur(function () {
            if (   $("#shopName").val()!=RepVo.data.shopName){
                myGetAjax(
                    "/catering_system_app/shopUser/checkShop",
                    {
                        shopName:$("#shopName").val()
                    },
                    checkShop
                )
            }
        });
        $("#editShop").click(function () {
            if ( $("span:eq(0)").text()!="商户名已存在") {
                myGetAjax(
                    "/catering_system_app/shopUser/changeShop",
                    {
                        shopName:$("#shopName").val(),
                        shopDivision:$("#shopDivision").val(),
                        brandName:$("#brandName").val(),
                        shopAddress:$("#shopAddress").val(),
                    },
                    editUser
                )
            }

        })
    })
}

function checkShop(RespVo) {
    if (RespVo.code=="100"){
        $("span:eq(0)").attr("style", "color:green");
        $("span:eq(0)").text("商户名可用");
    } else if (RespVo.code=="200"){
        $("span:eq(0)").attr("style", "color:red");
        $("span:eq(0)").text("商户名已存在");
    }
}
function editUser(RespVo) {
    if (RespVo.code=="200"){
        alert(RespVo.data);
    }else {
        alert(RespVo.msg);
    }
}